<?php
/**
 * @version $Id: install.unocart.php 22 2010-05-17 22:03:42Z vladzimirs@gmail.com $
 * @package UnoCart
 * @copyright Авторские права (C) 2009-2010 UnoCart team & (C) 2007-2010 Joostina team &. Все права защищены.
 * @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
 * UnoCart! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
 * Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл help/copyright.php.
 */
defined('_VALID_MOS') or die('Restricted access');

if (file_exists(JPATH_BASE . '/administrator/components/com_unocart/lang/admin_' .
    Jconfig::getInstance()->config_lang . '.php')) {
    require_once (JPATH_BASE . '/administrator/components/com_unocart/lang/admin_' .
        Jconfig::getInstance()->config_lang . '.php');
} else {
    require_once (JPATH_BASE .
        '/administrator/components/com_unocart/lang/admin_russian.php');
}


function updatePath($value)
{
    $path = 'js/ThemeOffice/';
    return $path . $value;
}

function updateIcons()
{
    global $database;
    $arr_images = array('unocart_logo_s.png', 'unocart_categories_s.png',
        'unocart_products_s.png', 'unocart_manufacturer_s.png', 'unocart_coupons_s.png',
        'unocart_configuration_s.png', 'unocart_orders_s.png', 'unocart_users_s.png',
        'unocart_info_s.png', 'unocart_report_s.png');
    $arr_links = array('option=com_unocart', 'option=com_unocart&act=categories',
        'option=com_unocart&act=products', 'option=com_unocart&act=manufacturers',
        'option=com_unocart&act=coupons', 'option=com_unocart&act=config',
        'option=com_unocart&act=orders', 'option=com_unocart&act=users',
        'option=com_unocart&act=info', 'option=com_unocart&act=report');
    $arr_names = array(_UNOCART_MENU_MAIN, _UNOCART_MENU_CATEGORIES,
        _UNOCART_MENU_PRODUCTS, _UNOCART_MENU_MANUFACTURERS, _UNOCART_MENU_COUPONS,
        _UNOCART_MENU_CONFIG, _UNOCART_MENU_ORDERS, _UNOCART_MENU_CLIENTS,
        _UNOCART_MENU_INFO, _UNOCART_MENU_WISHLIST);
    $arr_images = array_map("updatePath", $arr_images);

    foreach ($arr_images as $key => $value) {
        $query = "UPDATE `#__components`
		          SET `admin_menu_img` = '" . $arr_images[$key] . "', `name` = '" . $arr_names[$key] .
            "'
		          WHERE `admin_menu_link` = '" . $arr_links[$key] . "'";
        $database->setQuery($query);
        $database->query();
    }
}


function updatePaymentConstant()
{
    global $database;
    $query = "UPDATE `#__unocart_payment_method`
              SET `payment_name` = '" . _UNOCART_PAYMENT_BANK . "'
              WHERE `payment_code` = 'bank'";
    $database->setQuery($query);
    $database->query();

    $query = "UPDATE `#__unocart_payment_method`
              SET `payment_name` = '" . _UNOCART_PAYMENT_DEBIT . "'
              WHERE `payment_code` = 'debit'";
    $database->setQuery($query);
    $database->query();

    $query = "UPDATE `#__unocart_payment_method`
              SET `payment_name` = '" . _UNOCART_PAYMENT_PURCHASE . "'
              WHERE `payment_code` = 'PO'";
    $database->setQuery($query);
    $database->query();


    $query = "UPDATE `#__unocart_payment_method`
              SET `payment_name` = '" . _UNOCART_PAYMENT_PAYPAL . "'
              WHERE `payment_code` = 'paypal'";
    $database->setQuery($query);
    $database->query();
}

function updateConfig()
{
    global $database;
    if (file_exists(JPATH_BASE . '/administrator/components/com_unocart/lang/admin_' .
        Jconfig::getInstance()->config_lang . '.php')) {
        $lang = Jconfig::getInstance()->config_lang;
    } else {
        $lang = 'english';
    }
    $query = "UPDATE `#__unocart_config`
              SET `defaultLanguage` = '" . $lang . "',
                  `mainLanguage` = '" . $lang . "'";
    $database->setQuery($query);
    $database->query();
}

function com_install()
{
    @chmod(JPATH_BASE . '/components/com_unocart/images', 0755);
    @chmod(JPATH_BASE . '/components/com_unocart/images/categories',
        0755);
    @chmod(JPATH_BASE . '/components/com_unocart/images/products',
        0755);
    @chmod(JPATH_BASE . '/components/com_unocart/videos', 0755);
    @chmod(JPATH_BASE . '/components/com_unocart/videos/products',
        0755);

    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_logo_s.png', JPATH_BASE .
        '/includes/js/ThemeOffice/unocart_logo_s.png');

    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_categories_s.png', JPATH_BASE .
        '/includes/js/ThemeOffice/unocart_categories_s.png');
    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_configuration_s.png', JPATH_BASE .
        '/includes/js/ThemeOffice/unocart_configuration_s.png');
    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_coupons_s.png', JPATH_BASE .
        '/includes/js/ThemeOffice/unocart_coupons_s.png');
    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_manufacturer_s.png', JPATH_BASE .
        '/includes/js/ThemeOffice/unocart_manufacturer_s.png');
    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_orders_s.png', JPATH_BASE .
        '/includes/js/ThemeOffice/unocart_orders_s.png');
    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_products_s.png', JPATH_BASE .
        '/includes/js/ThemeOffice/unocart_products_s.png');
    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_users_s.png', JPATH_BASE .
        '/includes/js/ThemeOffice/unocart_users_s.png');
    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_info_s.png', JPATH_BASE .
        '/includes/js/ThemeOffice/unocart_info_s.png');
    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_report_s.png', JPATH_BASE .
        '/includes/js/ThemeOffice/unocart_report_s.png');

    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_categories_b.png', JPATH_BASE .
        '/administrator/images/unocart_categories_b.png');
 //   unlink(JPATH_BASE .
 //       '/administrator/components/com_unocart/images/unocart_categories_b.png');

    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_configuration_b.png', JPATH_BASE .
        '/administrator/images/unocart_configuration_b.png');
  //  unlink(JPATH_BASE .
  //      '/administrator/components/com_unocart/images/unocart_configuration_b.png');

    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_coupons_b.png', JPATH_BASE .
        '/administrator/images/unocart_coupons_b.png');
  //  unlink(JPATH_BASE .
  //      '/administrator/components/com_unocart/images/unocart_coupons_b.png');

    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_info_b.png', JPATH_BASE .
        '/administrator/images/unocart_info_b.png');
   // unlink(JPATH_BASE .
   //     '/administrator/components/com_unocart/images/unocart_info_b.png');

    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_manufacturer_b.png', JPATH_BASE .
        '/administrator/images/unocart_manufacturer_b.png');
   // unlink(JPATH_BASE .
   //     '/administrator/components/com_unocart/images/unocart_manufacturer_b.png');

    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_orders_b.png', JPATH_BASE .
        '/administrator/images/unocart_orders_b.png');
  //  unlink(JPATH_BASE .
   //     '/administrator/components/com_unocart/images/unocart_orders_b.png');

    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_products_b.png', JPATH_BASE .
        '/administrator/images/unocart_products_b.png');
  //  unlink(JPATH_BASE .
  //      '/administrator/components/com_unocart/images/unocart_products_b.png');

    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_users_b.png', JPATH_BASE .
        '/administrator/images/unocart_users_b.png');
   // unlink(JPATH_BASE .
    //    '/administrator/components/com_unocart/images/unocart_users_b.png');

    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_report_b.png', JPATH_BASE .
        '/administrator/images/unocart_report_b.png');
   // unlink(JPATH_BASE .
    //    '/administrator/components/com_unocart/images/unocart_report_b.png');

    copy(JPATH_BASE .
        '/administrator/components/com_unocart/images/unocart_panel.png', JPATH_BASE .
        '/administrator/images/unocart_panel.png');
   // unlink(JPATH_BASE .
    //    '/administrator/components/com_unocart/images/unocart_panel.png');


    updateIcons();
    updatePaymentConstant();
    updateConfig();
    // Install modules

    // End install modules
}

?>